package com.plugin.transformdemo;

import com.android.build.api.transform.Context;
import com.android.build.api.transform.QualifiedContent;
import com.android.build.api.transform.SecondaryInput;
import com.android.build.api.transform.Transform;
import com.android.build.api.transform.TransformException;
import com.android.build.api.transform.TransformInput;
import com.android.build.api.transform.TransformInvocation;
import com.android.build.api.transform.TransformOutputProvider;

import org.gradle.api.Project;

import java.io.IOException;
import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.Set;

public class TransformDemo extends Transform {

    Project project;

    Set<QualifiedContent.ContentType> sets = new LinkedHashSet<>();
    Set<QualifiedContent.Scope> set2 = new LinkedHashSet<>();
    Set<QualifiedContent.Scope> ref = new LinkedHashSet<>();


    public TransformDemo(Project project) {
        this.project = project;
        sets.add(QualifiedContent.DefaultContentType.CLASSES);
        ref.add(QualifiedContent.Scope.PROJECT);
        ref.add(QualifiedContent.Scope.SUB_PROJECTS);
        ref.add(QualifiedContent.Scope.PROVIDED_ONLY);
    }

    @Override
    public String getName() {
        return "TransformDemoImpl";
    }


    @Override
    public Set<QualifiedContent.ContentType> getInputTypes() {
        return sets;
    }

    @Override
    public Set<QualifiedContent.Scope> getScopes() {
        return set2;
    }

    @Override
    public Set<? super QualifiedContent.Scope> getReferencedScopes() {
        return ref;
    }


    @Override
    public boolean isIncremental() {
        return true;
    }

    @Override
    public void transform(TransformInvocation transformInvocation) throws TransformException, InterruptedException, IOException {
        super.transform(transformInvocation);
        TransformDemoPlugin.println("-------------transform TransformDemo------6-------");
        Context context = transformInvocation.getContext();
        Collection<TransformInput> inputs = transformInvocation.getInputs();
        TransformOutputProvider transformOutputProvider = transformInvocation.getOutputProvider();
        Collection<TransformInput> transformInputCollection = transformInvocation.getReferencedInputs();
        Collection<SecondaryInput> secondaryInputCollection = transformInvocation.getSecondaryInputs();
        TransformDemoPlugin.println("context=" + context);
        TransformDemoPlugin.println("inputs=" + inputs);
        TransformDemoPlugin.println("transformOutputProvider=" + transformOutputProvider);
        TransformDemoPlugin.println("transformInputCollection=" + transformInputCollection);
        TransformDemoPlugin.println("secondaryInputCollection=" + secondaryInputCollection);
    }
}
